<?php
require_once("lib/db_connection.php");
$wo_id = base64_decode($_GET['WO']);
$veh_id = base64_decode($_GET['veh']);
$pr = $_GET['pr'];
//die($pr);
$company_id = $_SESSION['company_id'];

$result_select = mysql_query("SELECT * FROM veh_workorder_tbl WHERE workorder_id='".$wo_id."'")
or die("SELECT WO ".mysql_error());
$row_wo = mysql_fetch_array($result_select);

$result_veh = mysql_query("SELECT * FROM vehicle_tbl WHERE vehicle_id='".$veh_id."'")
or die("SELECT VEH ".mysql_error());
$row_veh = mysql_fetch_array($result_veh);

$result_labor = mysql_query("SELECT * FROM veh_laborline_tbl WHERE workorder='".$wo_id."'")
or die("SELECT LABOR ".mysql_error());

$result_parts = mysql_query("SELECT * FROM veh_parts_tbl WHERE workorder='".$wo_id."'")
or die("SELECT PARTS ".mysql_error());

$result_misc = mysql_query("SELECT * FROM veh_misc_tbl WHERE workorder='".$wo_id."'")
or die("SELECT MISC ".mysql_error());

$result_comp = mysql_query("SELECT * FROM company_tbl WHERE company_id='".$company_id."'")
or die("SELECT COMPANY ".mysql_error());
$row_comp = mysql_fetch_array($result_comp);
?>
<html>
<head>
<script type="text/javascript">
function print_doc()
{
window.print();
}
</script>
</head>
<body onload='print_doc()'>
<table border='0' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
 <th width='100%' style='text-align:center;' colspan='3'><?php echo $row_comp['company_name']?></th>
</tr>
<tr>
 <th width='100%' style='text-align:center;' colspan='3'><?php echo $row_comp['address']?></th>
</tr>
<tr>
 <td width='33%' style='text-align:left;'>Contact No:<?php echo $row_comp['contact_no']?></td>
 <td width='34%' style='text-align:center;'><?php echo $row_comp['website']?></td>
 <td width='33%' style='text-align:right;'>Fax No:<?php echo $row_comp['fax_no']?></td>
</tr>
</table>
<?php
if($pr=='order')
{
?>
<img border="0" src="image/head.png" width="810" height="30" />
<?php
}?>
<?php
if($pr=='summary')
{?>
<img border="0" src="image/head_sum.png" width="810" height="30" />
<?php
}?>
<table border='0' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
 <td width='50%' style='text-align:left;'><b>Veh:<?php echo $row_veh['veh_num']?></b>
 &nbsp;&nbsp;<b><?php echo $row_veh['year']?>&nbsp;<?php echo $row_veh['manufacturer_name']?>&nbsp;<?php echo $row_veh['model_name']?></b>
 </td>
 <td width='50%' style='text-align:right;'><b>Reference No.:<?php echo $row_wo['order_num']?></b></td>
</tr>
</table>
<table border='0' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
<td  width='80%'>
<table border='0'  width='100%' style='font-size:14px;font-family:Times New Roman'>
<tr>
 <td width='40%'><b>Creation Date:</b> <?php echo $row_wo['creation_date']?></td>
 <td width='60%'><b>Odometer:</b> <?php echo $row_wo['odometer']?></td>
</tr>
<tr>
 <td width='40%'><b>Completion Date:</b> <?php echo $row_wo['completion_date']?></td>
 <td width='60%'><b>Serviced By:</b> <?php echo $row_wo['service_name']?></td>
</tr>
<tr>
 <td width='40%' colspan='3'><b>Description:</b> <?php echo $row_wo['description']?></td>
</tr>
<tr>
 <td width='40%' colspan='3'><b>Full Description:</b> <?php echo $row_wo['full_desc']?></td>
</tr>
</table>
</td>
</tr>
</table>
<br />
<img border="0" src="image/labor.png" width="810" height="23" />
<table border='1' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
 <th width='15%'>Date</th>
 <th width='35%'>Description</th>
 <th width='10%'>Qty</th>
 <th width='20%'>Unit Price</th>
 <th width='20%'>Amount</th>
</tr>
<?php
while($row_labor = mysql_fetch_array($result_labor))
{
?>
<tr>
 <td width='15%'><?php echo $row_labor['labor_date']?></td>
 <td width='35%'><?php echo $row_labor['description']?></td>
 <td width='10%' style='text-align:right;'><?php echo $row_labor['labor_unit']?></td>
 <td width='20%' style='text-align:right;'><?php echo $row_labor['cost']?></td>
 <td width='20%' style='text-align:right;'><?php echo $row_labor['total']?></td>
</tr>
<?php
}
?>
</table>
<br />
<img border="0" src="image/part.png" width="810" height="23" />
<table border='1' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
 <th width='15%'>Date</th>
 <th width='35%'>Description</th>
 <th width='10%'>Qty</th>
 <th width='20%'>Unit Price</th>
 <th width='20%'>Amount</th>
</tr>
<?php
while($row_parts = mysql_fetch_array($result_parts))
{
?>
<tr>
 <td width='15%'><?php echo $row_parts['parts_date']?></td>
 <td width='35%'><?php echo $row_parts['part_desc']?></td>
 <td width='10%' style='text-align:right;'><?php echo $row_parts['quantity']?></td>
 <td width='20%' style='text-align:right;'><?php echo $row_parts['price_ea']?></td>
 <td width='20%' style='text-align:right;'><?php echo $row_parts['amount']?></td>
</tr>
<?php
}
?>
</table>
<br />
<img border="0" src="image/misc.png" width="810" height="23" />
<table border='1' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
 <th width='15%'>Date</th>
 <th width='65%'>Description</th>
 <th width='20%'>Amount</th>
</tr>
<?php
while($row_misc = mysql_fetch_array($result_misc))
{
?>
<tr>
 <td width='15%'><?php echo $row_misc['date']?></td>
 <td width='65%'><?php echo $row_misc['description']?></td>
 <td width='20%' style='text-align:right;'><?php echo $row_misc['amount']?></td>
</tr>
<?php
}
?>
</table>
<br>
<table border='0' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>

<td width='80%'>
<table border='0' width='99%' style='font-size:14px;font-family:Times New Roman'><tr><td><b>Remarks:</b></td></tr><tr><td><textarea rows="5" cols="90" readonly="readonly" style="font-family:'Times New Roman'"><?php echo $row_wo['maint_custom1'] ?></textarea></td></tr></table>
</td>

<td width='20%'><table border='4' width='99%'>
<fieldset style='font-size:14px;font-family:Times New Roman'>
<legend>
<b>Charges/Billing</b>
</legend>
<b>Labor:</b> <?php echo $row_wo['labor']?>
<br />
<b>Parts:</b> <?php echo $row_wo['parts']?>
<br />
<b>Misc:</b> <?php echo $row_wo['misc']?>
<br />
<b>Discount:</b> <?php echo $row_wo['discount']?>
<br />
<b>Total:</b> <?php echo $row_wo['total']?>
</fieldset>
</table>
</td>
</tr>
</table>

<?php
if($pr=='order')
{
?>
<br />
<table border='0' width='810' style='font-size:14px;font-family:Times New Roman'>
<tr>
<td><b>Approved by</b></td></tr>
<tr><td>__________________________</td></tr>
</table>
<?php
}
if($pr=='summary')
{}
?>
<p style=" position: relative; bottom: 0; left: 0; width: 100%; text-align: center;"><img border="0" src="image/footer_wo.png" width="135" height="30" /></p>
</body>
</html>
<?php
?>